package models

import (
	__ "product-server/bsic/proto"

	"gorm.io/gorm"
)

type Product struct {
	gorm.Model
	ProductName string  `json:"Product"`
	Stock       string  `json:"Stock"`
	Price       float32 `json:"Price"`
	Image       string  `json:"Image"`
}

func (p *Product) ProductNameAdd(db *gorm.DB) error {

	return db.Debug().Create(p).Error

}

func (p *Product) ProductNameShow(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(p).Error
}

func (p *Product) ProductDel(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Delete(p).Error
}

func (p *Product) ProductUpdate(db *gorm.DB) error {
	return db.Debug().Updates(p).Error
}

func (p *Product) ProductList(db *gorm.DB, products []*__.ProductList) ([]*__.ProductList, error) {
	err1 := db.Debug().Model(&Product{}).Find(&products).Error

	return products, err1

}
